const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
    return sequelize.define(
        't_employee_transfer',
        {
            id: {
                autoIncrement: true,
                type: DataTypes.BIGINT,
                allowNull: false,
                primaryKey: true,
                comment: '异动ID',
            },
            emp_id: {
                type: DataTypes.BIGINT,
                allowNull: false,
                comment: '员工ID',
                references: {
                    model: 't_employee',
                    key: 'id',
                },
            },
            transfer_type: {
                type: DataTypes.TINYINT,
                allowNull: false,
                comment: '异动类型（关联字典表）',
            },
            before_info: {
                type: DataTypes.STRING(500),
                allowNull: true,
                comment: '变动前信息',
            },
            after_info: {
                type: DataTypes.STRING(500),
                allowNull: true,
                comment: '变动后信息',
            },
            reason: {
                type: DataTypes.STRING(500),
                allowNull: true,
                comment: '异动原因',
            },
            effective_date: {
                type: DataTypes.DATEONLY,
                allowNull: false,
                comment: '生效日期',
            },
            operator_id: {
                type: DataTypes.BIGINT,
                allowNull: true,
                comment: '操作人ID',
                references: {
                    model: 't_employee',
                    key: 'id',
                },
            },
            create_time: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
            },
            update_time: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
            },
        },
        {
            sequelize,
            tableName: 't_employee_transfer',
            timestamps: false,
            indexes: [
                {
                    name: 'PRIMARY',
                    unique: true,
                    using: 'BTREE',
                    fields: [{ name: 'id' }],
                },
                {
                    name: 'operator_id',
                    using: 'BTREE',
                    fields: [{ name: 'operator_id' }],
                },
                {
                    name: 'idx_emp',
                    using: 'BTREE',
                    fields: [{ name: 'emp_id' }],
                },
                {
                    name: 'idx_effective_date',
                    using: 'BTREE',
                    fields: [{ name: 'effective_date' }],
                },
            ],
        },
    );
};
